<%@ page import="java.util.*;" %>
<%@page contentType="text/plain" pageEncoding="UTF-8"%>
<%
    // print friends as a JSON string. Used for passing friends and firneds seach.
    // chose json becasue it's nice and easy to parse in javascript in comparison to xml.
    // [{"id": "1", "description": "this is a clue"}, {"id": "2", "description": "another clue"}]

            List<Map<String, String>> friends = (List<Map<String, String>>) request.getAttribute("friendslist");
            out.print("[");
            for (int i = 0; i < friends.size(); i++) {
                String friendName = friends.get(i).get("friendName");
                String friendLevel = friends.get(i).get("friendLevel");
                String friendScore = friends.get(i).get("friendScore");
                String friendPicture = friends.get(i).get("friendPicture");
                String friendOnline = friends.get(i).get("friendOnline");
                //formats json text so that there's key and text.
                String jsonDict = String.format("{\"friendName\": \"%s\", \"friendLevel\": \"%s\", \"friendScore\": \"%s\", \"friendPicture\": \"%s\", \"friendOnline\": \"%s\"}", friendName, friendLevel, friendScore, friendPicture, friendOnline);
                out.print(jsonDict);
                if (i + 1 < friends.size()) {
                    out.print(", ");
                }
            }
            out.print("]");
%>
